let mockUsers = [
    { id: 1, username: 'test', password: '123456', email: 'test@example.com' },
    { id: 2, username: 'admin', password: 'admin', email: 'admin@example.com' }
];

export function login(data) {
    return new Promise((resolve) => {
        setTimeout(() => {
            if (!data.username || !data.password) {
                return resolve({ code: 400, message: '用户名和密码不能为空' });
            }
            const user = mockUsers.find(u => u.username === data.username && u.password === data.password);
            if (user) {
                resolve({
                    code: 200,
                    token: `token_${user.id}`,
                    userInfo: { id: user.id, username: user.username, email: user.email }
                });
            } else {
                resolve({ code: 400, message: '用户名或密码错误' });
            }
        }, 500);
    });
}

export function register(data) {
    return new Promise((resolve) => {
        setTimeout(() => {
            if (!data.username || !data.password || !data.email) {
                return resolve({ code: 400, message: '请完善注册信息' });
            }
            if (mockUsers.some(u => u.username === data.username)) {
                return resolve({ code: 400, message: '用户名已存在' });
            }
            const newUser = { id: mockUsers.length + 1, ...data };
            mockUsers.push(newUser);
            resolve({ code: 200, message: '注册成功' });
        }, 500);
    });
}